package longrise.phone.com.bjjt_henan.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.CommontUtils;

/**
 * 我的收藏列表的适配器
 */
public class MyCollectAdapter extends BaseAdapter {

    private Context mContext;

    private List<EntityBean> lists;

    public MyCollectAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<EntityBean> beans) {
        this.lists = beans;
    }

    @Override
    public int getCount() {
        return (lists == null) ? 0 : lists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_mycollect_item, null);
            holder.typeIV = (ImageView) convertView.findViewById(R.id.mycollect_item_iv_icon);
            holder.timeTV = (TextView) convertView.findViewById(R.id.mycollect_item_tv_time);
            holder.titleTV = (TextView) convertView.findViewById(R.id.mycollect_item_tv_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //设置数据
        EntityBean bean = lists.get(position);
        //图片
        String url = bean.getString("imgtitle");
        if (!TextUtils.isEmpty(url)) {
            ImageLoader.getInstance().displayImage(url, holder.typeIV, CommontUtils.getOptions());
        }
        //标题
        String title = bean.getString("title");
        if (TextUtils.isEmpty(title)) {
            title = "";
        }
        holder.titleTV.setText(title);
        //时间
        String ctime = bean.getString("createtime");
        if (TextUtils.isEmpty(ctime)) {
            ctime = "";
        }
        holder.timeTV.setText(ctime);

        return convertView;
    }

    private class ViewHolder {
        private ImageView typeIV;//图片
        private TextView titleTV;//文章标题
        private TextView timeTV;//时间
    }
}
